from collections import defaultdict

from common.mssql_helper import g_msql_inst
from common.utils import create_uuid

__author__ = "Ypf"
_date_ = "2019/7/23-14:46"

class Cgtj(object):
    @staticmethod
    def get_dic_gys(sql):
        # 获取相应的对比sql查询语句
        res_list1 = g_msql_inst.fetch_all(sql)
        dic = defaultdict(dict)
        for (gongys_name,jiashui_heji) in res_list1:
            if gongys_name=='':
                pass
            else:
                dic[gongys_name]=[gongys_name,jiashui_heji]
        return  dic

    @staticmethod
    def insert_cg(dic, db_insert_sql, nowtime):
        for key in dic:
            id = create_uuid()
            dic[key].append(nowtime + '-01')
            dic[key].append(id)
            value_tuple = tuple(dic[key])
            excuete_sql = db_insert_sql % value_tuple
            print(excuete_sql)
            g_msql_inst.db_excuete(excuete_sql)
    @staticmethod
    def check_cf(sql):
        res_list1 = g_msql_inst.fetch_all(sql)
        dic = defaultdict(dict)
        for (sjsj) in res_list1:
            if sjsj == '':
                dic=None
            else:
                dic[sjsj] = [sjsj]
        return dic

    @staticmethod
    def get_gys_pp():
        # 获取相应的对比sql查询语句
        res_list1 = g_msql_inst.fetch_all("select pp,cpgly from k3_gysry")
        dic = defaultdict(dict)
        for (pp,cpgly) in res_list1:
            if pp == '':
                pass
            else:
                dic[pp] = [cpgly]
        return dic

    @staticmethod
    def get_gys_gys():
        # 获取相应的对比sql查询语句
        res_list1 = g_msql_inst.fetch_all("select gys,cpgly from k3_gyry")
        dic = defaultdict(dict)
        for (gys,cpgly) in res_list1:
            if gys == '':
                pass
            else:
                dic[gys] = [cpgly]
        return dic
